using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
    /// <summary>
    /// Controller class for CX_UserLogin
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class CxUserLoginController
    {
        // Preload our schema..
        CxUserLogin thisSchemaLoad = new CxUserLogin();
        private string userName = String.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}
					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}
				}
				return userName;
            }
        }
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public CxUserLoginCollection FetchAll()
        {
            CxUserLoginCollection coll = new CxUserLoginCollection();
            Query qry = new Query(CxUserLogin.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public CxUserLoginCollection FetchByID(object Guid)
        {
            CxUserLoginCollection coll = new CxUserLoginCollection().Where("guid", Guid).Load();
            return coll;
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public CxUserLoginCollection FetchByQuery(Query qry)
        {
            CxUserLoginCollection coll = new CxUserLoginCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object Guid)
        {
            return (CxUserLogin.Delete(Guid) == 1);
        }
        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object Guid)
        {
            return (CxUserLogin.Destroy(Guid) == 1);
        }
        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(Guid Guid,int? Uid,string Username,string Ip,string LoginOK,DateTime? Intime)
	    {
		    CxUserLogin item = new CxUserLogin();
		    
            item.Guid = Guid;
            
            item.Uid = Uid;
            
            item.Username = Username;
            
            item.Ip = Ip;
            
            item.LoginOK = LoginOK;
            
            item.Intime = Intime;
            
	    
		    item.Save(UserName);
	    }
    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(Guid Guid,int? Uid,string Username,string Ip,string LoginOK,DateTime? Intime)
	    {
		    CxUserLogin item = new CxUserLogin();
	        item.MarkOld();
	        item.IsLoaded = true;
		    
			item.Guid = Guid;
				
			item.Uid = Uid;
				
			item.Username = Username;
				
			item.Ip = Ip;
				
			item.LoginOK = LoginOK;
				
			item.Intime = Intime;
				
	        item.Save(UserName);
	    }
    }
}
